package com.atguigu.app;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.atguigu.customer.bean.Customer;

import java.util.List;

public class JSONDemo {


    public static void main(String[] args) {
        String json = "{\"name\":\"zhangsan\",\"age\":18}";
        Customer customer = JSON.parseObject(json, Customer.class);
        JSONObject jsonObject = JSON.parseObject(json);
        System.out.println("customer = " + customer);
        System.out.println("jsonObject = " + jsonObject);

        String jsonarr = "[{\"name\":\"zhangsan\",\"age\":18}]";
        List<Customer> customerList = JSON.parseArray(jsonarr, Customer.class);
        List<JSONObject> customerJsonList = JSON.parseArray(jsonarr, JSONObject.class);

        System.out.println("customerList = " + JSON.toJSONString(customerList) );



    }
}
